package com.example.boardroom.serial.table;

import android.util.SparseArray;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.example.boardroom.serial.table.manager.DAM3200Manager;

import java.util.HashMap;

public class DAM3200Table {
    public long id;

    public String sRecTime;
    public String hexFrame;//16位
    public String status;//状态
    public String DAM0 = "故障";//8
    public String DAM1 = "故障";//7
    public String DAM2 = "故障";//6
    public String DAM3 = "故障";//5
    public String DAM4 = "故障";//4
    
    public String DAM5 = "故障";//3
    
    public String DAM6 = "故障";//2
    
    public String DAM7 = "故障";//1
    
    public String DAM8 = "故障";//16
    
    public String DAM9 = "故障";//15
    
    public String DAM10 = "故障";//14
    
    public String DAM11 = "故障";//13
    
    public String DAM12 = "故障";//12
    
    public String DAM13 = "故障";//11
    
    public String DAM14 = "故障";//10"故障"
    
    public String DAM15 = "故障";//9
    
    public String DAM23 = "故障";//7
    
    public String DAM22 = "故障";//6
    
    public String DAM21= "故障";//5
    
    public String DAM20= "故障";//4\
    
    public String DAM19= "故障";//3
    
    public String DAM18= "故障";//2
    
    public String DAM17= "故障";//1
    
    public String DAM16= "故障";//2ma


    //    public String DAM32= "故障";//16
    
    public String DAM31= "故障";//15
    
    public String DAM30 = "故障";//14
    
    public String DAM29 = "故障";//13
    
    public String DAM28 = "故障";//12
    
    public String DAM27 = "故障";//11
    
    public String DAM26 = "故障";//1"故障"
    
    public String DAM25 = "故障";//9
    
    public String DAM24 = "故障";//8

    private HashMap<String,String> hashMap;
    //解答模型
    //0 1 2 3  4 5 6 7  8 9 10 11 12131415     16 171819    20 21 22 23   24  25 26 27    28 29 30 31
    //1 0 0 0  0 0 0 0  0 0 0 0    1 0 0 0     0  0  0  0    0  0  0  1   1  0  0  0      0  0  0  0
    //7 6 5 4  3 2 1 0  15141312   11 10 9 8   23 22 21 20   19  18 17 16  31 30 29 28     27 26 25 24
//00000000000000000000000000000000

    public HashMap<String, String> getHashMap() {
        return hashMap;
    }

    public DAM3200Table() {
    }

    //左 DO2  右DO1
    public DAM3200Table(String sRecTime, String toHex) {
        hashMap=new HashMap<>();
        if (StringUtils.isEmpty(sRecTime)){
            this.sRecTime =  TimeUtils.getNowString();
        }else {
            this.sRecTime=sRecTime;
        }
        this.hexFrame = toHex.replace(" ","");
        DAM3200Manager manager = new DAM3200Manager();
        String dam3200 = manager.translateDAM3200(hexFrame);
        if (dam3200.equals("0")) {
            status = "错误";

        } else {
            status = "正常";
            SparseArray<String> sparseArray = new SparseArray<>(32);//存储32位状态的
            for (int i = 0; i < dam3200.length(); i++) {
                sparseArray.put(i, String.valueOf(dam3200.charAt(i)));
            }

            DAM0 = String.valueOf(dam3200.charAt(7));
            DAM1 = String.valueOf(dam3200.charAt(6));
            DAM2 = String.valueOf(dam3200.charAt(5));
            DAM3 = String.valueOf(dam3200.charAt(4));
            DAM4 =String.valueOf(dam3200.charAt(3));
            DAM5 = String.valueOf(dam3200.charAt(2));
            DAM6 = String.valueOf(dam3200.charAt(1));
            DAM7 = String.valueOf(dam3200.charAt(0));

            DAM8 = String.valueOf(dam3200.charAt(15));
            DAM9 = String.valueOf(dam3200.charAt(14));
            DAM10 =String.valueOf(dam3200.charAt(13));
            DAM11 =String.valueOf(dam3200.charAt(12));

            DAM12 = String.valueOf(dam3200.charAt(11));
            DAM13 =String.valueOf(dam3200.charAt(10));
            DAM14 =String.valueOf(dam3200.charAt(9));
            DAM15 =String.valueOf(dam3200.charAt(8));

            DAM23 = String.valueOf(dam3200.charAt(16));//7
            DAM22 = String.valueOf(dam3200.charAt(17));//6
            DAM21= String.valueOf(dam3200.charAt(18));//5
            DAM20= String.valueOf(dam3200.charAt(19));//4


            DAM19= String.valueOf(dam3200.charAt(20));//3
            DAM18= String.valueOf(dam3200.charAt(21));//2
            DAM17= String.valueOf(dam3200.charAt(22));//1
            DAM16 =String.valueOf(dam3200.charAt(23));

            DAM31= String.valueOf(dam3200.charAt(24));//15
            DAM30 = String.valueOf(dam3200.charAt(25));//14
            DAM29 = String.valueOf(dam3200.charAt(26));//13
            DAM28 = String.valueOf(dam3200.charAt(27));//12


            DAM27 = String.valueOf(dam3200.charAt(28));//11
            DAM26 = String.valueOf(dam3200.charAt(29));//1String.valueOf(dam3200.charAt(i))
            DAM25 = String.valueOf(dam3200.charAt(30));//9
            DAM24 = String.valueOf(dam3200.charAt(31));//8
            hashMap.put("DAM0",DAM0);
            hashMap.put("DAM1",DAM1);
            hashMap.put("DAM2",DAM2);
            hashMap.put("DAM3",DAM3);
            hashMap.put("DAM4",DAM4);
            hashMap.put("DAM5",DAM5);
            hashMap.put("DAM6",DAM6);
            hashMap.put("DAM7",DAM7);
            hashMap.put("DAM8",DAM8);
            hashMap.put("DAM9",DAM9);
            hashMap.put("DAM10",DAM10);
            hashMap.put("DAM11",DAM11);
            hashMap.put("DAM12",DAM12);
            hashMap.put("DAM13",DAM13);
            hashMap.put("DAM14",DAM14);
            hashMap.put("DAM15",DAM15);
            hashMap.put("DAM16",DAM16);
            hashMap.put("DAM17",DAM17);
            hashMap.put("DAM18",DAM18);
            hashMap.put("DAM19",DAM19);
            hashMap.put("DAM20",DAM20);
            hashMap.put("DAM21",DAM21);
            hashMap.put("DAM22",DAM22);
            hashMap.put("DAM23",DAM23);
            hashMap.put("DAM24",DAM24);
            hashMap.put("DAM25",DAM25);
            hashMap.put("DAM26",DAM26);
            hashMap.put("DAM27",DAM27);
            hashMap.put("DAM28",DAM28);
            hashMap.put("DAM29",DAM29);
            hashMap.put("DAM30",DAM30);
            hashMap.put("DAM31",DAM31);

        }

    }

    @Override
    public String toString() {
        return "DAM3200Table{" +
                "id=" + id +
                ", sRecTime='" + sRecTime + '\'' +
                ", hexFrame='" + hexFrame + '\'' +
                ", status='" + status + '\'' +
                ", DAM0='" + DAM0 + '\'' +
                ", DAM1='" + DAM1 + '\'' +
                ", DAM2='" + DAM2 + '\'' +
                ", DAM3='" + DAM3 + '\'' +
                ", DAM4='" + DAM4 + '\'' +
                ", DAM5='" + DAM5 + '\'' +
                ", DAM6='" + DAM6 + '\'' +
                ", DAM7='" + DAM7 + '\'' +
                ", DAM8='" + DAM8 + '\'' +
                ", DAM9='" + DAM9 + '\'' +
                ", DAM10='" + DAM10 + '\'' +
                ", DAM11='" + DAM11 + '\'' +
                ", DAM12='" + DAM12 + '\'' +
                ", DAM13='" + DAM13 + '\'' +
                ", DAM14='" + DAM14 + '\'' +
                ", DAM15='" + DAM15 + '\'' +
                ", DAM23='" + DAM23 + '\'' +
                ", DAM22='" + DAM22 + '\'' +
                ", DAM21='" + DAM21 + '\'' +
                ", DAM20='" + DAM20 + '\'' +
                ", DAM19='" + DAM19 + '\'' +
                ", DAM18='" + DAM18 + '\'' +
                ", DAM17='" + DAM17 + '\'' +
                ", DAM16='" + DAM16 + '\'' +
                ", DAM31='" + DAM31 + '\'' +
                ", DAM30='" + DAM30 + '\'' +
                ", DAM29='" + DAM29 + '\'' +
                ", DAM28='" + DAM28 + '\'' +
                ", DAM27='" + DAM27 + '\'' +
                ", DAM26='" + DAM26 + '\'' +
                ", DAM25='" + DAM25 + '\'' +
                ", DAM24='" + DAM24 + '\'' +
                '}';
    }
}
